package io.esirong.util;

import android.util.Log;

public class ViewUtils {
    private static long lastClickTime = 0;
    private static long DIFF = 1000;
    private static int lastViewId = -1;

    /**
     * 判断两次点击的间隔，如果小于1000，则认为是多次无效点击
     *
     * @return true 短时间内多次点击
     */
    public static boolean isFastClick() {
        return isFastClick(-1, DIFF);
    }

    /**
     * 判断两次点击的间隔，如果小于1000，则认为是多次无效点击
     *
     * @return true 短时间内多次点击
     */
    public static boolean isFastClick(int buttonId) {
        return isFastClick(buttonId, DIFF);
    }

    /**
     * 判断两次点击的间隔，如果小于diff，则认为是多次无效点击
     *
     * @param diff 时长（毫秒）
     * @return true 短时间内多次点击
     */
    public static boolean isFastClick(int viewId, long diff) {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (lastViewId == viewId && lastClickTime > 0 && timeD < diff) {
            Log.v("isFastDoubleClick", "短时间内按钮多次触发");
            return true;
        }

        lastClickTime = time;
        lastViewId = viewId;
        return false;
    }

}
